#include "CGridMap.h"

#include <QDebug>

CGridMap::CGridMap()
{
    m_size_x = 0;
    m_size_y = 0;

    clearVector(m_data);
}

CGridMap::CGridMap(quint16 size_x, quint16 size_y)
{
    m_size_x = size_x;
    m_size_y = size_y;

    m_data = QVector<quint8> (m_size_x * m_size_y, 255);
}

CGridMap::~CGridMap()
{
    clearVector(m_data);
}


void CGridMap::initGridMap(quint16 height, quint16 width)
{
    clearVector(m_data);

    m_size_x = width;
    m_size_y = height;

    m_data = QVector<quint8> (m_size_x * m_size_y, 255);
}

void CGridMap::updateGridMapData(QVector<QPoint> obstacle_list)
{
    qDebug("[CGridMap] updateGridMapData enter, obstacle_list size:%d\n", obstacle_list.size());
    if (m_data.capacity() == 0)
    {
        return;
    }

    for (auto &each : obstacle_list)
    {
        quint32 index = each.y() * m_size_x + each.x();

        if (index < (quint32)m_data.capacity())
        {
            m_data[index] = 0;
        }
    }
}

void CGridMap::resetMap()
{
    clearVector(m_data);
    m_data = QVector<quint8> (m_size_x * m_size_y, 255);
}
